;
(function () {
  new Vue({
    el: '#yxCreate',
    data: {
      yxState: {
        list: [{
          name: '整租',
          code: 'ER'
        }, {
          name: '工位',
          code: 'WR'
        }],
        active: 'ER'
      },
      yxzlfState: {
        list: [{
          name: '公司租赁',
          code: 'QY'
        }, {
          name: '个人租赁',
          code: 'PE'
        }],
        active: 'QY'
      },
      projectList: [],
      projectParams: {
        id: null,
        name: null,
        flag: false
      },
      buildingList: [],
      buildingParams: {
        id: null,
        name: null,
        flag: false
      },
      floorList: [],
      floorParams: {
        id: null,
        name: null,
        flag: false
      },
      unitList: [],
      unitParams: {
        id: null,
        name: null,
        flag: false
      },
      positinList: [],
      selectedUnitList: [],
      unitIds: [],
      queryUnitParams: {
        ids: [],
        list: []
      },
      wpIds: [],
      wpItem: [],
      queryWpParams: {
        ids: [],
        list: []
      },
      stIds: [],
      stItem: [],
      queryStParams: {
        ids: [],
        list: []
      },
      industryList: [],
      industryAct: '',
      channelType: [], //渠道分类
      channerCode: '',
      channerName: [], //渠道名称
      channerNameCode: [],
      channelnameVal: '',
      customers: [],
      acreage: '',
      stcount: '',
      memo: '',
      yxamount: '',
      dkamount: '',
      customer: '',
      idcode: '',
      email: '',
      lgperson: '',
      lsperson: '',
      lgphone: '',
      lsphone: '',
      address: '',
      zlfId: '',
      zlfName: '',
      wpflag: false,
      stflag: false,
      customersFlag: false,
      stateflag: false,
      state: null,
      errData: {},

      beginTime: '',
      endTime: '',
      lastTime: '',


      fileList: [],
      progress: '',
    },
    methods: {
      // 上传文件
      uploadFile: function () {
        if (this.progress) {
          hl.toast('文件尚未上传完成')
          return
        }
        $('.upload-file-button').trigger('click')
      },
      delFileItem(index) {
        this.fileList.splice(index, 1)
      },
      //获取默认信息
      getInfo() {
        var data1 = JSON.parse(sessionStorage.getItem('RENT_BU_UNIT_MES'));
        var data2 = JSON.parse(sessionStorage.getItem('RENT_UNIT_MES'));
        this.yxState.active = data1.contractType
        this.acreage = data2.unit_acreage.toFixed(2)
        this.projectList.forEach(item => {
          if (item.projectId == data1.projectId) {
            this.$refs.yxProject.innerHTML = item.projectName
            this.projectParams = {
              id: data1.projectId,
              name: item.projectName,
              flag: false
            }
          }
        })
        this.queryUnitParams = {
          ids: [data1.units.unit_id],
          list: [{
            buildingId: data1.units.building_id,
            buildingName: data1.units.building_name,
            floorId: data1.units.floor_id,
            floor: data1.units.floor_name,
            floorNum: data1.units.floor_num,
            acreage: data1.units.unit_acreage,
            unitId: data1.units.unit_id,
            unitName: data1.units.unit_name
          }]
        }
      },
      // 设置合同工位状态
      setYxState(val) {
        this.yxState.active = val;
        this.queryUnitParams = {
          ids: [],
          list: []
        }
        this.queryWpParams = {
          ids: [],
          list: []
        }
        this.queryStParams = {
          ids: [],
          list: []
        }
        this.stIds = []
        this.stItem = []
        this.wpIds = []
        this.wpItem = []
        this.emptyParams()
      },
      // 设置租赁方状态
      setYxzlfState(val) {
        this.yxzlfState.active = val;
      },
      //获取项目
      getProject() {
        hlhttp.get({
          url: 'user/projects',
          success: (res) => {
            this.projectList = res;
            if (sessionStorage.getItem('RENT_BU_UNIT_MES')) {
              this.getInfo()
            }
          }
        })
      },
      //获取楼宇
      getBuilding() {
        hlhttp.get({
          url: 'project/buildings',
          data: {
            project_id: this.projectParams.id
          },
          success: (res) => {
            this.buildingList = res;
          }
        })
      },
      //获取楼层
      getFloor() {
        hlhttp.get({
          url: 'building/floors',
          data: {
            project_id: this.projectParams.id,
            building_id: this.buildingParams.id
          },
          success: (res) => {
            this.floorList = res;
          }
        })
      },
      // 获取单元
      getUnit() {
        hlhttp.get({
          url: 'floor/units',
          data: {
            project_id: this.projectParams.id,
            building_id: this.buildingParams.id,
            floor_id: this.floorParams.id
          },
          success: (res) => {
            res.map(item => {
              item.buildingName = this.buildingParams.name;
            })
            if (!res.length) return;
            if (!this.wpflag && !this.stflag) {
              this.unitList = filterUnitPosition(res, 'BU', 'unitType');
            }
            if (this.wpflag) {
              this.unitList = filterUnitPosition(res, 'WP', 'unitType');
            }
            if (this.stflag) {
              this.unitList = filterUnitPosition(res, 'ST', 'unitType');
            }
          }
        })
      },
      //获取工位车位
      getPosition() {
        hlhttp.get({
          url: 'units/positions',
          data: {
            unit_id: this.unitParams.id
          },
          success: (res) => {
            res.map(item => {
              item.unitId = this.unitParams.id
              item.unitName = this.unitParams.name
              item.buildingName = this.buildingParams.name
              item.floor = this.floorParams.name
              item.buildingId = this.buildingParams.id
              item.floorId = this.floorParams.id
            })
            if (this.wpflag) {
              this.positinList = filterUnitPosition(res, 'WP', 'positionType')
            }
            if (this.stflag) {
              this.positinList = filterUnitPosition(res, 'ST', 'positionType')
            }
          }
        })
      },
      getIndustryData() {
        hlhttp.get({
          url: 'configure/industry/dict',
          success: data => {
            this.industryList = data;
          }
        })
      },
      //渠道分类
      getChannelTypeData() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'ZHSH',
            config_name: 'ZS_CHANNEL_CATE'
          },
          success: data => {
            this.channelType = data;
          }
        })
      },
      //渠道名称
      getChannelNameData() {
        var self = this
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'ZHSH',
            config_name: 'ZS_CHANNEL_NAME'
          },
          success: data => {
            let arr = []
            data.map(item => {
              if (item.status == 'Y') {
                arr.push(item)
              }
            })
            self.channerNameList = hlArrayUtil.replaceData(arr, [{
              key: 'dictName',
              rKey: 'name'
            }, {
              key: 'dictCode',
              rKey: 'code'
            }])
          }
        })
      },
      //项目id，name获取
      getProjectParams(ops) {
        if (ops.projectId == this.projectParams.id) return;
        this.projectParams = {
          id: ops.projectId,
          name: ops.projectName,
          flag: false
        }
        this.queryUnitParams = {
          ids: [],
          list: []
        }
        this.queryWpParams = {
          ids: [],
          list: []
        }
        this.queryStParams = {
          ids: [],
          list: []
        }
        this.stIds = []
        this.stItem = []
        this.wpIds = []
        this.wpItem = []
        this.emptyParams()
      },
      //楼宇id， name获取
      getBuildingParams(ops) {
        this.buildingParams = {
          id: ops.buildingId,
          name: ops.name,
          flag: true
        }
        if (this.buildingParams.flag) this.getFloor()
      },
      //楼层id， name获取
      getFloorParams(ops) {
        this.floorParams = {
          id: ops.floorId,
          name: ops.floorName,
          flag: true
        }
        if (this.floorParams.flag) this.getUnit()
      },
      //单元id， name获取
      getunitParams(ops) {
        this.unitParams = {
          id: ops.unitId,
          name: ops.unitName,
          flag: true
        }
        if (this.unitParams.flag) this.getPosition()
      },
      //显示关闭单元弹窗
      changeProjectFlag() {
        if (!this.projectParams.id){
          hl.toast('请先选择意向项目');
          return;
        }

        this.projectParams.flag = !this.projectParams.flag;
        if (this.projectParams.flag) {
          this.getBuilding()
          if (this.queryUnitParams.ids.length) {
            this.selectedUnitList = JSON.parse(JSON.stringify(this.queryUnitParams.list))
            this.unitIds = JSON.parse(JSON.stringify(this.queryUnitParams.ids))
          }
        }
        if (!this.projectParams.flag) {
          this.emptyParams()
        }
      },
      emptyParams() {
        this.buildingParams = {
          id: null,
          name: null,
          flag: false
        }
        this.floorParams = {
          id: null,
          name: null,
          flag: false
        }
        this.$refs.building.innerHTML = '请选择'
        this.$refs.floor.innerHTML = '请选择'
        this.$refs.building1.innerHTML = '请选择'
        this.$refs.floor1.innerHTML = '请选择'
        this.$refs.building2.innerHTML = '请选择'
        this.$refs.floor2.innerHTML = '请选择'
        this.$refs.unit.innerHTML = '请选择'
        this.$refs.unit1.innerHTML = '请选择'
        this.buildingList = []
        this.floorList = []
        this.unitList = []
        this.selectedUnitList = []
        this.unitIds = []
        this.positinList = []
      },
      //显示关闭工位弹窗
      changeWpFlag() {
        if (!this.projectParams.id){
          hl.toast('请先选择意向项目');
          return;
        }

        this.wpflag = !this.wpflag
        if (this.wpflag) {
          this.getBuilding()
          if (this.queryWpParams.ids.length) {
            const items = JSON.parse(JSON.stringify(this.queryWpParams.list))
            this.wpItem = []
            items.forEach(item => {
              item.children.map(item0 => {
                this.wpItem.push({
                  buildingId: item.buildingId,
                  buildingName: item.buildingName,
                  companyName: item.companyName,
                  contractId: item.contractId,
                  flag: item.flag,
                  floor: item.floor,
                  floorId: item.floorId,
                  positionId: item0.positionId,
                  positionName: item0.positionName,
                  positionType: item.positionType,
                  rentState: item.rentState,
                  rentType: item.rentType,
                  unitId: item.unitId,
                  unitName: item.unitName
                })
              })
            })

            this.wpIds = JSON.parse(JSON.stringify(this.queryWpParams.ids))
          }
        }
        if (!this.wpflag) {
          this.emptyParams()
        }
      },
      //显示关闭车位
      changeStFlag() {
        if (!this.projectParams.id){
          hl.toast('请先选择意向项目');
          return;
        }
        
        this.stflag = !this.stflag
        if (this.stflag) {
          this.getBuilding()
          if (this.queryStParams.ids.length) {
            const items = JSON.parse(JSON.stringify(this.queryStParams.list))
            this.stItem = []
            items.forEach(item => {
              item.children.map(item0 => {
                this.stItem.push({
                  buildingId: item.buildingId,
                  buildingName: item.buildingName,
                  companyName: item.companyName,
                  contractId: item.contractId,
                  flag: item.flag,
                  floor: item.floor,
                  floorId: item.floorId,
                  positionId: item0.positionId,
                  positionName: item0.positionName,
                  positionType: item.positionType,
                  rentState: item.rentState,
                  rentType: item.rentType,
                  unitId: item.unitId,
                  unitName: item.unitName
                })
              })
            })
            this.stIds = JSON.parse(JSON.stringify(this.queryStParams.ids))
          }
        }
        if (!this.stflag) {
          this.emptyParams()
        }
      },
      //选中单元
      selectedUnit(ops) {
        if (this.unitIds.indexOf(ops.unitId) > -1) {
          this.selectedUnitList = toHeavy(this.selectedUnitList, ops.unitId, 'unitId')
          this.unitIds = toFilter(this.unitIds, ops.unitId)
          return
        }
        this.unitIds.push(ops.unitId)
        this.selectedUnitList.push(ops)
      },
      //确认选中的单元
      queryUnit() {
        this.queryUnitParams = {
          ids: JSON.parse(JSON.stringify(this.unitIds)),
          list: JSON.parse(JSON.stringify(this.selectedUnitList))
        }
        this.changeProjectFlag()
      },
      //删除已选单元
      deleteUnit(i) {
        this.queryUnitParams.ids.splice(i, 1);
        this.queryUnitParams.list.splice(i, 1);
      },
      // 选中工位
      selectWpPosition(ops) {
        if (this.wpIds.indexOf(ops.positionId) > -1) {
          this.wpItem = toHeavy(this.wpItem, ops.positionId, 'positionId')
          this.wpIds = toFilter(this.wpIds, ops.positionId)
          return
        }
        this.wpIds.push(ops.positionId)
        this.wpItem.push(ops)
      },
      // 选中车位
      selectStPosition(ops) {
        if (this.stIds.indexOf(ops.positionId) > -1) {
          this.stItem = toHeavy(this.stItem, ops.positionId, 'positionId')
          this.stIds = toFilter(this.stIds, ops.positionId)
          return
        }
        this.stIds.push(ops.positionId)
        this.stItem.push(ops)
      },
      //确认选中的工位
      queryWp() {
        let newArr = hlArrayUtil.removeRepeat(this.wpItem, 'unitId')
        newArr.map(item => {
          item.children = []
        })
        this.wpItem.map(item => {
          newArr.map(item1 => {
            if (item.unitId == item1.unitId) {
              item1.children.push({
                positionName: item.positionName,
                positionId: item.positionId
              })
            }
          })
        })
        this.queryWpParams = {
          ids: JSON.parse(JSON.stringify(this.wpIds)),
          list: JSON.parse(JSON.stringify(newArr))
        }
        this.changeWpFlag()
      },
      //确认选中的车位
      querySt() {
        let newArr = hlArrayUtil.removeRepeat(this.stItem, 'unitId')
        newArr.map(item => {
          item.children = []
        })
        this.stItem.map(item => {
          newArr.map(item1 => {
            if (item.unitId == item1.unitId) {
              item1.children.push({
                positionName: item.positionName,
                positionId: item.positionId
              })
            }
          })
        })
        this.queryStParams = {
          ids: JSON.parse(JSON.stringify(this.stIds)),
          list: JSON.parse(JSON.stringify(newArr))
        }
        this.changeStFlag()
      },
      //删除工位
      deleteWp(i0, i1, id) {
        this.queryWpParams.list[i0].children.splice(i1, 1)
        let ids = this.queryWpParams.ids;
        for (var i = 0; i < ids.length; i++) {
          if (ids[i] == id) {
            ids.splice(i, 1)
          }
        }
        if (!this.queryWpParams.list[i0].children.length) {
          this.queryWpParams.list.splice(i0, 1)
        }
      },
      //删除车位
      deleteSt(i0, i1, id) {
        this.queryStParams.list[i0].children.splice(i1, 1)
        let ids = this.queryStParams.ids;
        for (var i = 0; i < ids.length; i++) {
          if (ids[i] == id) {
            ids.splice(i, 1)
          }
        }
        if (!this.queryStParams.list[i0].children.length) {
          this.queryStParams.list.splice(i0, 1)
        }
      },
      //金额同步
      blur() {
        if (Number(this.yxamount) < 0) {
          this.yxamount = 0
          hl.toast('金额不能为负数')
        }
        if (!this.dkamount) {
          this.dkamount = this.yxamount
        }
      },
      blurdkamount() {
        if (Number(this.dkamount) < 0) {
          this.dkamount = 0
          hl.toast('金额不能为负数')
        }
      },
      //设置渠道
      setchanner(val,code,name) {
        this.channerCode = val;
        this.channerNameCode = [];
        this.channelnameVal = ''
        this.channerName = [];
        this.channerNameList.map(item => {
          if (item.parentDictCode == val) {
            this.channerName.push(item)
          }
        })
        if(code){
          this.handleChannelNameChange([{
            code:code,
            name:name
          }])
         }
      },
      handleChannelNameChange(ops) {
        this.channerNameCode = ops[0].code
        this.channelnameVal = ops[0].name
      },
      hideYx() {
        this.stateflag = false;
      },
      //保存
      saveYxData(state) {
        let units, wps;

        if (this.yxState.active == 'ER') {
          units = [];
          let unitOlist = this.queryUnitParams.list;
          unitOlist.map(item => {
            units.push({
              "building_id": item.buildingId,
              "building_name": item.buildingName,
              "floor_id": item.floorId,
              "floor_num": item.floor.toString(),
              "unit_id": item.unitId,
              "unit_name": item.unitName,
              "unit_acreage": item.acreage ? item.acreage.toString() : item.unitAcreage.toString()
            })
          })
          wps = '#'
        }
        if (this.yxState.active == 'WR') {
          units = '#'
          var wpArr = this.queryWpParams.list;
          wps = [];
          wpArr.map(item => {
            item.children.map(item1 => {
              wps.push({
                building_id: item.buildingId,
                building_name: item.buildingName,
                floor_id: item.floorId,
                floor_num: item.floor.toString(),
                wp_acreage: '0',
                unit_id: item.unitId,
                unit_name: item.unitName,
                wp_id: item1.positionId,
                wp_name: item1.positionName
              })
            })
          })
        }
        var stop = [];
        var stArr = this.queryStParams.list;
        stArr.map(item => {
          item.children.map(item1 => {
            stop.push({
              building_id: item.buildingId,
              building_name: item.buildingName,
              floor_id: item.floorId,
              floor_num: item.floor.toString(),
              stop_acreage: '0',
              unit_id: item.unitId,
              unit_name: item.unitName,
              stop_id: item1.positionId,
              stop_name: item1.positionName
            })
          })
        })
        if (!stop.length) {
          stop = '#'
        }
        var zlfData = {
          zlf_type: this.yxzlfState.active,
          zlf_id: this.zlfId || '#',
          zlf_name: this.customer || '#',
          zlf_lperson: this.lgperson || '#',
          zlf_sperson: this.lsperson || '#',
          zlf_lphone: this.lgphone || '#',
          zlf_sphone: this.lsphone || '#',
          zlf_industry_type: this.industryAct,
          zlf_address: this.address || '#',
          idcode: this.idcode || '#',
          email: this.email || '#',
          channel_category_code: this.channerCode,
          channel_name_code: this.channerNameCode.length ? this.channerNameCode[0] : '#',
          channel_name_value: this.channelnameVal || '#'
        };
        var projectData = {
          project_id: this.projectParams.id || '#',
          project_name: this.projectParams.name || '#',
          units: JSON.stringify(units),
          wps: JSON.stringify(wps),
          stops: JSON.stringify(stop)
        };
        if (state == 'CF') {
          if (!this.projectParams.id) {
            hl.toast('请选择项目')
            return
          }
          if (this.yxState.active == 'ER') {
            if (!units.length) {
              hl.toast('请选择单元')
              return
            }
          }
          if (this.yxState.active == 'WR') {
            if (!wps.length) {
              hl.toast('请选择工位')
              return
            }
          }
          if (!this.beginTime) {
            hl.toast('请选择需求时间')
            return
          }
          if (!this.endTime) {
            hl.toast('请选择需求时间')
            return
          }
          if (!this.yxamount) {
            hl.toast('请填写意向金金额')
            return
          }
          if (!this.dkamount) {
            hl.toast('请填写可抵扣金额')
            return
          }
          if (!this.lastTime) {
            hl.toast('请选择最晚缴纳时间')
            return
          }
        }
        if (!this.customer) {
          hl.toast('请填写客户名称')
          return
        }
        // if (!this.idcode) {
        //   hl.toast('请填写纳税人识别号/身份证号')
        //   return
        // }
        if (!this.address) {
          hl.toast('请填写通讯地址')
          return
        }
        let data = {
          project_id: this.projectParams.id || '#',
          project_name: this.projectParams.name || '#',
          intent_type: this.yxState.active,
          intent_acreage: this.acreage || '#',
          intent_parking_num: this.stcount || '#',
          zlf_info: JSON.stringify(zlfData),
          project_info: JSON.stringify(projectData),
          intent_start_date: this.beginTime || '#',
          intent_end_date: this.endTime || '#',
          intent_amount: this.yxamount || '#',
          intent_deductible_amount: this.dkamount || '#',
          intent_payment_deadline: this.lastTime || '#',
          memo: this.memo || '#'
        }
        let url;
        if (state == 'CF') {
          url = 'contract/intent/_submit '
        }
        if (state == 'CG') {
          url = 'contract/intent'
        }
        hlhttp.post({
          url: url,
          data,
          success: (res) => {
            this.saveFile(res.id)
            hlUrlUtil.goTo('yxDetail', {
              id: res.id,
              ddtab: true
            }, false)
          },
          error: (err) => {
            var res = JSON.parse(err.responseText)
            if (res.code != 'INFO_WRONG' && res.code != 'UNIT_RENTED') {
              hl.toast(res.msg)
              return
            }

            if (state != 'CF') {
              hl.toast(res.msg)
              return
            }
            if (state == 'CF') {
              this.stateflag = true;
              if (res.code == 'INFO_WRONG') {
                this.state = 1;
              }
              if (res.code == 'UNIT_RENTED') {
                this.state = 2;
                this.errData = JSON.parse(res.msg);
              }
            }
          }
        })
      },
      // 保存相关文件
      saveFile(id) {
        if (!this.fileList.length) return
        let data = {
          intent_id: id,
          attachment_name: '',
          attachment_url: '',
        }
        let name = [],
          url = []

        this.fileList.map(item => {
          name.push(item.name)
          url.push(item.url)
        })

        data.attachment_name = name + ''
        data.attachment_url = url + ''

        hlhttp.post({
          url: 'intent/attachment',
          data: data,
          success: res => {

          }
        })
      },
      //获取公司名字
      inputCname: function () {
        var flag = true;
        var permissions = JSON.parse(window.localStorage.getItem('permissions'));
        for (var i = 0; i < permissions.length; i++) {
          if (permissions[i] == 'c43') {
            flag = false;
          }
        }
        if (flag) {
          return
        }
        var _this = this;
        len = this.customer;
        this.zlfId = '';
        this.industryAct = '';
        this.lsperson = '';
        this.lsphone = '';
        this.lgperson = '';
        this.lgphone = '';
        this.idcode = '';
        this.email = '';
        this.$refs.industry.innerHTML = '请选择';
        this.$refs.channelType.innerHTML = '请选择';
        this.channerCode = '';
        this.channerNameCode = [];
        this.channelnameVal = ''
        if (!this.customer) {
          _this.customersFlag = false;
          return
        }
        if (isNull(this.customer)) {
          _this.customersFlag = false;
          return
        }
        if (len.length != len.length + 1) {
          hlhttp.get({
            url: 'customers/_search',
            data: {
              begin_date: '#', //付款开始日期
              end_date: '#', //付款结束日期
              key_word: _this.customer.trim(), //关键字
              customer_state: '#', //客户状态
              black_state: '#', //Y黑名单客户，N不是黑名单
              page: 1, //请求页 Int
              page_size: 10000, //每页数量 Int
              rperson_ids: '#',
              columns: '#',
              orders: '#'
            },
            success: (data) => {
              var temp = data.customers;
              var str = '';
              if (!temp.length) {
                return
              }

              _this.customers = temp;
              _this.customersFlag = true;
              for (var i = 0; i < temp.length; i++) {
                if (temp[i].name === _this.customer) {
                  this.industryAct = temp[i].industryCode;
                  this.yxzlfState.active = temp[i].type;
                  this.zlfId = temp[i].id;
                  this.lsperson = temp[i].legalPersonName;
                  this.lgphone = temp[i].phone;
                  this.lgperson = temp[i].lperson;
                  this.idcode = temp[i].idcode;
                  this.email = temp[i].email;
                  this.channerCode = temp[i].channelCategoryCode;
                  this.channerNameCode = temp[i].channelNameCode ? temp[i].channelNameCode.split() : [];
                  this.channelnameVal = temp[i].channelNameVal;
                  this.$refs.channelType.innerHTML = temp[i].channelCategoryVal || '请选择';
                  this.$refs.industry.innerHTML = temp[i].industryVal || '请选择';
                  this.address = temp[i].address
                }
              }
            }
          })
        }
      },
      //点击获取公司
      setClickCname: function (name) {
        this.customer = name;
        for (var i = 0; i < this.customers.length; i++) {
          if (this.customers[i].name === this.customer) {
            this.industryAct = this.customers[i].industryCode;
            this.yxzlfState.active = this.customers[i].type;
            this.zlfId = this.customers[i].id;
            this.lsperson = this.customers[i].legalPersonName;
            this.lgphone = this.customers[i].phone;
            this.lgperson = this.customers[i].lperson;
            this.idcode = this.customers[i].idcode;
            this.email = this.customers[i].email;
            this.channerCode = this.customers[i].channelCategoryCode;
            this.channerNameCode = this.customers[i].channelNameCode ? this.customers[i].channelNameCode.split() : [];
            this.channelnameVal = this.customers[i].channelNameVal;
            this.$refs.channelType.innerHTML = this.customers[i].channelCategoryVal || '请选择';
            this.$refs.industry.innerHTML = this.customers[i].industryVal || '请选择';
            this.address = this.customers[i].address
          }
        }
        this.customersFlag = false;
        event.stopPropagation()
        if(this.channerCode){
          this.setchanner(this.channerCode,this.channerNameCode,this.channelnameVal)
        }
      },
      //客户详情跳转过来的
      customerInfo() {
        let data = JSON.parse(unescape(hlUrlUtil.GetQueryString('params')))
        this.zlfId = data.id
        this.yxzlfState.active = data.code;
        this.customer = data.name;
        this.$refs.industry.innerHTML = data.industryName;
        this.industryAct = data.industryType;
        this.idcode = data.icode;
        this.email = data.email;
        this.lgperson = data.lperson;
        this.lgphone = data.phone;
        this.lsperson = data.lperson;
        this.lsphone = data.phone;
        this.$refs.channelType.innerHTML = data.channelCategoryVal;
        this.channelnameVal = data.channelNameVal;
        this.channerCode = data.channelCategoryCode;
        this.channerNameCode = data.channelNameCode.length ? data.channelNameCode.split() : [];
        this.address = data.address;
      },
      //租控跳转过来的
      rentInfo() {
        let unit = JSON.parse(unescape(hlUrlUtil.GetQueryString('unit')))
        let posotion = JSON.parse(unescape(hlUrlUtil.GetQueryString('posotion')))
        this.projectParams = {
          id: unit.projectId,
          name: unit.projectName,
          flag: false
        }
        this.$refs.yxProject.innerHTML = unit.projectName

        function positionArr() {
          let tempArr = [],
            newArr = [],
            ids = []
          posotion.map(item => {
            tempArr.push({
              positionId: item.positionId,
              positionName: item.positionName
            })
            ids.push(item.positionId)
          })
          newArr = [{
            buildingId: unit.buildingId,
            buildingName: unit.buildingName,
            floorId: unit.floorId,
            floor: unit.floorName,
            floorNum: unit.floorNum,
            children: tempArr,
            unitAcreage: unit.unitAcreage,
            unitId: unit.unitId,
            unitName: unit.unitName
          }]
          return [newArr, ids]
        }
        if (unit.unitType == 'ST') {
          this.queryStParams = {
            ids: positionArr()[1],
            list: positionArr()[0]
          }
        }
        if (unit.unitType == 'WP') {
          this.queryWpParams = {
              ids: positionArr()[1],
              list: positionArr()[0]
            },
            this.yxState.active = 'WR'
        }
      }
    },
    created() {
      if (hlUrlUtil.GetQueryString('clear')) {
        window.sessionStorage.clear()
      }
      hlSelectUi()
    },
    mounted() {
      this.getProject()
      if (hlUrlUtil.GetQueryString('params')) {
        this.customerInfo()
      }
      if (localStorage.getItem('yxCreateData')) {
        let data0 = JSON.parse(localStorage.getItem('yxCreateData'))
        hlUrlUtil.addURLParam({
          'unit': escape(JSON.stringify(data0.unit)),
          'posotion': escape(JSON.stringify(data0.posotion))
        })
        sessionStorage.setItem('yxCreateData', localStorage.getItem('yxCreateData'))
        setTimeout(() => {
          this.rentInfo()
        }, 200)
        localStorage.removeItem('yxCreateData')
      }
      if (hlUrlUtil.GetQueryString('posotion')) {
        this.rentInfo()
      }


      this.getIndustryData()
      this.getChannelTypeData()
      this.getChannelNameData()
      document.addEventListener('click', (e) => {
        this.customersFlag = false;
      })

      let _this = this
      fileUpload('.upload-file-button', uploadUrl, function (res) {
        _this.progress = ''
        _this.fileList.push(res.json)
      }, function (val) {
        _this.progress = parseInt((val.loaded / val.total) * 100) + '%'
      })
    }
  })
}())

function filterUnitPosition(arr, type, key) {
  let newArr = [];
  arr.forEach(item => {
    if (item[key] == type) {
      item.flag = false;
      newArr.push(item)
    }
  })
  return newArr
}

function toHeavy(arr, val, type) {
  var newArr = arr;
  for (var i = 0; i < newArr.length; i++) {
    if (newArr[i][type] == val) {
      newArr.splice(i, 1)
    }
  }
  return newArr
}

function toFilter(arr, val) {
  var newArr = arr;
  for (var i = 0; i < newArr.length; i++) {
    if (newArr[i] == val) {
      newArr.splice(i, 1)
    }
  }
  return newArr
}

function isNull(str) {
  if (str == "") return true;
  var regu = "^[ ]+$";
  var re = new RegExp(regu);
  return re.test(str);
}
